package Day25;

import java.util.*;

public class Main {

    public static void main (String[] args) {

        Scanner in = new Scanner(System.in);

        while (in.hasNextLine()) {
            long n = Long.parseLong(in.nextLine());
            System.out.println(getRoot(n));
        }

    }

    public static long getRoot (long n) {
        //个位数直接返回
        if ((n / 10)  == 0) {
            return n;
        }
        //非个位数则每一位相加再递归
        else {
            long sum = 0;
            while (n != 0) {
                sum += (n % 10);
                n /= 10;
            }
            return getRoot(sum);
        }
    }

}